package top.humbleyuan.backtrack;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author HumbleYuan
 * @Date 2020/5/18 20:04
 * @Des 集合子集
 */
public class LeetCode_78 {
    public static void main(String[] args) {
        int[] nums = {1,2,3};

        List<List<Integer>> res = new ArrayList<>();

        // 回溯
        dfs(nums, new ArrayList<>(), res, 0);
        System.out.println(res.toString());
    }

    public static void dfs(int[] nums, List<Integer> list, List<List<Integer>> res, int index) {
        if(nums.length == index) {
            return;
        }

        for (int i = index; i < nums.length; i++) {
            list.add(nums[i]);
            res.add(new ArrayList<>(list));

            // dfs
            dfs(nums, list, res, ++index);

            // 回溯
            list.remove(list.size() - 1);
        }

    }
}
